package com.cxb.service;

import android.app.AlarmManager;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.*;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.*;
import android.location.GpsStatus.NmeaListener;
import android.os.*;
import android.os.Handler.Callback;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.amitek.aidl.mqtt.MqttServiceEvent;
import com.amitek.aidl.mqtt.MqttServiceProxy;
import com.amitek.aidl.mqtt.bean.AlarmData;
import com.amitek.aidl.mqtt.bean.UploadType;
import com.cxb.entity.Gps;
import com.cxb.entity.GpsStack;
import com.cxb.gsensor.AccelerationEventChange;
import com.cxb.gsensor.DrivingHehaviorAnalysiser3;
import com.cxb.gsensor.DrivingHehaviorAnalysiser3.DriverEvent;
import com.cxb.gsensor.DrivingHehaviorAnalysiser3.DriverResultCallBack;
import com.cxb.manager.CxbEventBus;
import com.cxb.manager.NavigationManager;
import com.cxb.manager.PhoneManager;
import com.cxb.mqtt.MqttCallBack;
import com.cxb.utils.*;
import com.cxb.utils.Debug;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import org.xutils.common.Callback.CommonCallback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;

public class CXBMainService extends Service implements NmeaListener, Callback,
        AccelerationEventChange {

    // 是否运行线程
    private boolean isRun, isFixed;
    private LocationManager manager;
    private Location currentLocation, lastLocation;
    private SharedPreferencesUtils sp;
    private DBHelp dbHelp;
    private static String lastCommandId;
    private int lastType;
    private SensorManager sensorManager;
    String imei = null;
    private String gravityDataStr = "";
    private HttpEngineUtils httpEngineUtils;
    private TelephonyManager telephonyManager;
    private boolean mGpsTimeSyncFlag = true;
    private static boolean isCarStart = false;
    private NavigationManager navigationManager;
    String nema;
    private Handler mHandler;
    private final int MSG_TYPE_RESET_GPS = 1;
    private GpsStack gpsStack = new GpsStack();
    private PhoneManager phoneManager;
    private Timer timer;
    private DateFormat formatter = new SimpleDateFormat("HH:mm:ss");

    private static final String TAG = "CXBMainService";
    private ActionReceiver mActionReceiver;
    private DrivingHehaviorAnalysiser3 drivingHehaviorAnalysiserA,
            drivingHehaviorAnalysiserD;
    private double weatherLoctionLa = 0.0;
    private double weatherLoctionLo = 0.0;
    private final int MAXDELAY = 50;
    private final int MAXUPDATEDELAY = 413;
    private int updatedelay = MAXUPDATEDELAY;
    private boolean weatherGetable = false;
    private int delay = MAXDELAY;
    private int effectivecount = 20;
    private static MqttServiceProxy mqttProxy;

    @Override
    public void onCreate() {
        super.onCreate();
        showCXBRunning();
        isRun = true;
        sp = new SharedPreferencesUtils(CXBMainService.this);
        dbHelp = new DBHelp(this);
        httpEngineUtils = new HttpEngineUtils(this);
        telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        navigationManager = new NavigationManager(this);
        manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        // 重要函数，监听数据测试
        manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0,
                locationListener);
        manager.addGpsStatusListener(statusListener);
        manager.addNmeaListener(this);
        phoneManager = new PhoneManager(this);
        imei = telephonyManager.getDeviceId();

        timer = new Timer();
        timer.schedule(new CheckGpsTask(), 0, 3000);

        mHandler = new Handler(this);

        sensorManager.registerListener(myAccelerometerListener,
                sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                (int) (1000000 * DrivingHehaviorAnalysiser3.INTERVAL / 2));

        sensorManager.registerListener(mMagneticListener,
                sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                SensorManager.SENSOR_DELAY_NORMAL);
        Debug.printfGPSLog("created \n");

        // 驾驶行为分析

        // float[] args = { 1.8f, // 减速阈值
        // -3.5f, // 加速阈值
        // 0.5f, // 减速窗口值
        // 2.1f, // 加速窗口值
        // 1 / 256f, // 减速低通滤波参考值_Z
        // 1 / 256f, // 减速低通滤波参考值_XY
        // 1 / 256f }; // 加速低通滤波参考值_XY
        // acceleration = new AccelerationRunnable(args, this);
        // // acceleration_bre = new Acceleration(2.0f, 0.0f,0.7f,1/256f,
        // 1/256f,
        // // Acceleration.MONITOR_BRE);
        //
        // acceleration_check = new AcceleratedCheck(acceleration);
        // acceleration.setGpsable(true);
        // acceleration_check.start();

        drivingHehaviorAnalysiserA = new DrivingHehaviorAnalysiser3();
        drivingHehaviorAnalysiserD = new DrivingHehaviorAnalysiser3();

		drivingHehaviorAnalysiserD.setDetectMode(DriverEvent.ACC);
		drivingHehaviorAnalysiserA.setDetectMode(DriverEvent.DEC);

        drivingHehaviorAnalysiserA.setCallBack(new DriverResultCallBack() {

            @Override
            public void onEvent(DriverEvent event) {
                if (event.equals(DriverEvent.DEC)) {
                    onBrake();
                }
            }
        });

        drivingHehaviorAnalysiserD.setCallBack(new DriverResultCallBack() {

            @Override
            public void onEvent(DriverEvent event) {
                if (event.equals(DriverEvent.ACC)) {
                    onAccelerate();
                }
            }
        });
        initBroadCast();

        bindMqttService();
    }

    private void initBroadCast() {
        mActionReceiver = new ActionReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(com.cxb.utils.Constants.CXBBroadcast.SHAREVIDEO);
        intentFilter
                .addAction(com.cxb.utils.Constants.CXBBroadcast.SHAREPICTURE);
        intentFilter
                .addAction(com.cxb.utils.Constants.CXBBroadcast.STARTNAVIGATION);
        this.registerReceiver(mActionReceiver, intentFilter);
    }

    float gsensorX;
    float gsensorY;
    float gsensorZ;
    float magneticX;
    float magneticY;
    float magneticZ;
    private Location preLocation;
    SensorEventListener mMagneticListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            magneticX = event.values[0];
            magneticY = event.values[1];
            magneticZ = event.values[2];

        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
        }
    };

    long preTime = -1;
    SensorEventListener myAccelerometerListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (preTime <= 0) {
                preTime = System.currentTimeMillis();
            }
            if ((System.currentTimeMillis() - preTime) / 1000.0 < DrivingHehaviorAnalysiser3.INTERVAL) {
                return;
            }
            gsensorX = event.values[0];
            gsensorY = event.values[1];
            gsensorZ = event.values[2];

            // if (acceleration != null) {
            // // acceleration.addData(gsensorX, gsensorY, gsensorZ);
            // }
            drivingHehaviorAnalysiserA.pushData(gsensorZ);
            drivingHehaviorAnalysiserD.pushData(gsensorZ);

        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
        }
    };
    // class

    GpsStatus gpsStatus = null;
    GpsStatus.Listener statusListener = new GpsStatus.Listener() {
        public void onGpsStatusChanged(int event) {
            // Log.i("test", "gps event=" + event);
            switch (event) {
                case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
                    // Log.i("test", "gps GPS_EVENT_SATELLITE_STATUS");

                    break;
                case GpsStatus.GPS_EVENT_FIRST_FIX:
                    isFixed = true;
                    break;
                case GpsStatus.GPS_EVENT_STARTED:
                    isFixed = false;
                    CxbEventBus.getCxbBus(CxbEventBus.EVENT_GPS_CHANGE).post(
                            new Integer(-1));
                    break;
                case GpsStatus.GPS_EVENT_STOPPED:
                    isFixed = false;
                    CxbEventBus.getCxbBus(CxbEventBus.EVENT_GPS_CHANGE).post(
                            new Integer(-1));
                    break;
            }
        }
    };
    private final LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            updateLocation(location);
            isFixed = true;
        }

        public void onProviderDisabled(String provider) {
            updateLocation(null);
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
            switch (status) {
                case LocationProvider.AVAILABLE:
                    isFixed = true;
                    break;
                case LocationProvider.OUT_OF_SERVICE:
                    isFixed = false;
                    CxbEventBus.getCxbBus(CxbEventBus.EVENT_GPS_CHANGE).post(
                            new Integer(-1));
                    // mGsensorCalculatorManager.setSpeed(0);
                    break;
                case LocationProvider.TEMPORARILY_UNAVAILABLE:
                    isFixed = false;
                    CxbEventBus.getCxbBus(CxbEventBus.EVENT_GPS_CHANGE).post(
                            new Integer(-1));
                    // mGsensorCalculatorManager.setSpeed(0);
                    break;
            }
        }
    };

    public void onDestroy() {
        manager.removeGpsStatusListener(statusListener);
        this.unregisterReceiver(mActionReceiver);
    }

    ;

    // 获取用户位置的函数，利用Log显示

    private void updateLocation(Location location) {

        CxbEventBus.getCxbBus(CxbEventBus.EVENT_GPS_CHANGE).post(
                new Integer(-2));
        if (location != null) {

            if (currentLocation == null) {
                sendBroadcast(new Intent("ami.intent.action.GPS_OK"));
            }
            currentLocation = location;
            if (location.getSpeed() >= 2) {
                CxbEventBus.getCxbBus(CxbEventBus.EVENT_GPS_CHANGE).post(
                        new Integer((int) location.getBearing()));
            }
            // mGsensorCalculatorManager.setSpeed(currentLocation.getSpeed());

            if (drivingHehaviorAnalysiserA != null) {
                drivingHehaviorAnalysiserA.setCurrentSpeed(currentLocation
                        .getSpeed());
            }
            if (drivingHehaviorAnalysiserD != null) {
                drivingHehaviorAnalysiserD.setCurrentSpeed(currentLocation
                        .getSpeed());
            }
            Log.d("hugo_app", "GPS time sync is enabled");
            if (location.getTime() > 0 && mGpsTimeSyncFlag) {
                try {

					mGpsTimeSyncFlag = false;
					Calendar c = Calendar.getInstance();
					c.setTimeInMillis(location.getTime());
//					long when = c.getTimeInMillis();
//					if (when / 1000 < Integer.MAX_VALUE) {
//						AlarmManager am = (AlarmManager) this
//								.getSystemService(Context.ALARM_SERVICE);
//						am.setTime(when);
//						am.setTimeZone("GMT+8");
//					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}

        if (location != preLocation) {
            // recorderGps(location);
            preLocation = location;
        }
        /** 是否获取天气主要决定于　weatherGetable **/
        if (location != null) {
            /** 如果之前没有GPS数据，一但得到数据就会激活weatherGetable **/
            if (weatherLoctionLa == 0.0 || weatherLoctionLo == 0.0) {
                weatherLoctionLa = location.getLatitude();
                weatherLoctionLo = location.getLongitude();
                sp.setLanLo(weatherLoctionLa, weatherLoctionLo);
                weatherGetable = true;
            } else if (delay-- < 0) {
                /** 行程大于100公里 **/
                if (CommonUtils.getDistance(sp.getLongitude(),
                        sp.getLatitude(), location.getLongitude(),
                        location.getLatitude()) > 100000.0) {
                    weatherLoctionLa = location.getLatitude();
                    weatherLoctionLo = location.getLongitude();
                    sp.setLanLo(weatherLoctionLa, weatherLoctionLo);
                    weatherGetable = true;
                }
                delay = MAXDELAY;

            }
            /** 天气数据没有效 **/
            else if (!sp.isWeatherEffective()) {
                if (effectivecount-- < 0) {
                    weatherGetable = true;
                    effectivecount = 30;
                }
            }
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    boolean uploadCurrentLocation = true;

    long updateGpsTime = System.currentTimeMillis();

    private void recorderGps(Location location) {

        if (location != null) {

            int height = (int) location.getAltitude();// 高度
            float speed = location.getSpeed();// 速度
            int direction = (int) location.getBearing();

            Gps gps = new Gps();
            gps.angle = direction;
            gps.lat = location.getLatitude();
            gps.lng = location.getLongitude();
            gps.height = height;
            gps.speed = speed;
            Bundle extras = location.getExtras();
            int satellitesNum = extras.getInt("satellites", 0);
            gps.sateliteCount = satellitesNum;
            try {

                gps.pdop = Float.parseFloat(CommonUtils.roundTwo(PDOP));
                gps.hdop = Float.parseFloat(CommonUtils.roundTwo(HDOP));
                gps.vdop = Float.parseFloat(CommonUtils.roundTwo(VDOP));
                gps.mode = locationMode;
                gps.time = System.currentTimeMillis() + "";
            } catch (Exception e) {
                e.printStackTrace();
            }
            dbHelp.addGps(gps);

        }

    }

    public boolean isGpsBad() {
        gpsStatus = manager.getGpsStatus(null);
        int count = 0;
        boolean result = true;
        if (gpsStatus != null) {
            Iterator satellites = gpsStatus.getSatellites().iterator();
            count = 0;

            while (satellites.hasNext()) {
                GpsSatellite satellite = (GpsSatellite) satellites.next();

                float pn = satellite.getSnr();
                Log.i("test", "gps snr=" + satellite.getSnr());
                if (satellite.getSnr() > 0) {
                    result = false;
                    count++;
                }
            }

        }
        if (count <= 1) {
            result = true;
        }
        Log.i("test", "gps status result=" + result + "  count=" + count);
        return result;

    }

    private int locationMode;
    private float PDOP, HDOP, VDOP;
    private long lastNmeaTime = 0;

    @Override
    public void onNmeaReceived(long timestamp, String nmea) {
        try {

            lastNmeaTime = System.currentTimeMillis();
            if (nmea != null && nmea.startsWith("$GPGSA")) {
                String[] str = nmea.split(",");
                locationMode = Integer.parseInt(str[2]);
                PDOP = Float.parseFloat(str[str.length - 3]);
                HDOP = Float.parseFloat(str[str.length - 2]);
                String vdopStr = str[str.length - 1];
                VDOP = Float.parseFloat(vdopStr.substring(0,
                        vdopStr.lastIndexOf("*")));
                Debug.printfGPSLog(nmea + "\n");
            }
            // this.nema = nmea;
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void showCXBRunning() {
        System.currentTimeMillis();
        Notification localNotification = new Notification();
        localNotification.flags = (0x2 | localNotification.flags);
        Context localContext = getApplicationContext();
        Intent localIntent = new Intent();
        localNotification.setLatestEventInfo(localContext, "", "",
                PendingIntent.getActivity(getApplicationContext(), 0,
                        localIntent, 0));

        startForeground(1, localNotification);
    }

    int hot_reset_count = 0;

    @Override
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            case MSG_TYPE_RESET_GPS:
                // manager.removeGpsStatusListener(statusListener);
                // manager.removeUpdates(locationListener);
                Log.i("test", " MSG_TYPE_RESET_GPS" + isGpsBad());
                if (!isGpsBad()) {
                    return true;
                }
                try {
                    manager.sendExtraCommand(LocationManager.GPS_PROVIDER,
                            "delete_aiding_data", null);
                    hot_reset_count++;
                    Log.i("test", "gps hot_reset_count=" + hot_reset_count);

                    if (hot_reset_count > 8) {
                        hot_reset_count = 0;
                        Settings.Secure.setLocationProviderEnabled(
                                getContentResolver(), LocationManager.GPS_PROVIDER,
                                false);
                        mHandler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                try {

                                    Settings.Secure.setLocationProviderEnabled(
                                            getContentResolver(),
                                            LocationManager.GPS_PROVIDER, true);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                            }
                        }, 1000);
                        mHandler.postDelayed(new Runnable() {

                            @Override
                            public void run() {

                                try {
                                    Log.i("test", "gps register");
                                    manager.requestLocationUpdates("gps", 3000L,
                                            0.0F, locationListener);
                                    manager.addGpsStatusListener(statusListener);
                                    sendBroadcast(new Intent("EVENT_GPS_RESET"));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                            }
                        }, 20000);
                    } else {
                        mHandler.postDelayed(new Runnable() {

                            @Override
                            public void run() {

                                try {
                                    manager.requestLocationUpdates("gps", 1000L,
                                            0.0F, locationListener);
                                    manager.addGpsStatusListener(statusListener);
                                    sendBroadcast(new Intent("EVENT_GPS_RESET"));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                            }
                        }, 1000);
                    }

                } catch (Exception e2) {
                    e2.printStackTrace();
                }

            default:
                break;
        }
        return false;
    }

    class CheckGpsTask extends TimerTask {
        @Override
        public void run() {
            try {

                // 判断gps状态
                if (lastNmeaTime != 0
                        && (System.currentTimeMillis() - lastNmeaTime > 600000)) {
                    lastNmeaTime = System.currentTimeMillis();
                    if (!getGpsState()) {
                        setGpsEnable(true);
                    } else {
                        Debug.printfGPSLog("GPS going reset --" + "");
                        reseGPS();
                    }
                }

                /** 获得天气存放在全局变量中 **/
                if (weatherGetable || updatedelay-- < 0) {
                    double la = sp.getLatitude();
                    double lo = sp.getLongitude();

                    if (lo != 0.0 && la != 0.0) {

                        String weatherUrl = "http://service.ami-tek.com.cn/weather?deviceId="
                                + imei + "&lat=" + la + "&lng=" + lo;
                        Log.d("pumkid", "weather url=" + weatherUrl);
                        RequestParams requestParams = new RequestParams(weatherUrl);
                        x.http().get(requestParams, new CommonCallback<String>() {

                            @Override
                            public void onSuccess(String result) {
                                sp.setStringWeather(result,
                                        System.currentTimeMillis());
                                Intent intent = new Intent();
                                intent.setAction("com.cxb.weatherUpdate");
                                CXBMainService.this
                                        .sendBroadcast(intent);
                            }

                            @Override
                            public void onError(Throwable throwable, boolean b) {
                                updatedelay = 30;
                            }

                            @Override
                            public void onCancelled(CancelledException e) {

                            }

                            @Override
                            public void onFinished() {

                            }
                        });

                    }
                    weatherGetable = false;
                    updatedelay = MAXUPDATEDELAY;
                }

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }

    public boolean getGpsState() {

        ContentResolver resolver = getContentResolver();
        boolean open = Settings.Secure.isLocationProviderEnabled(resolver,
                LocationManager.GPS_PROVIDER);
        Debug.printfGPSLog("GPS state is open ? " + open);
        return open;
    }

    public void setGpsEnable(boolean enable) {
        ContentResolver resolver = getContentResolver();
        Settings.Secure.setLocationProviderEnabled(resolver,
                LocationManager.GPS_PROVIDER, enable);
        if (enable)
            Debug.printfGPSLog("GPS has reset --");
        else
            Debug.printfGPSLog("set GPS off --");
    }

    public void reseGPS() {
        // setGpsEnable(false);
        // mHandler.postDelayed(new Runnable() {
        //
        // @Override
        // public void run() {
        // setGpsEnable(true);
        //
        // }
        // }, 5000);

        fullResetGps();
    }

    public void fullResetGps() {
        Debug.printfGPSLog("fullResetGps --");
        Bundle extras = new Bundle();
        extras.putBoolean("all", true);
        manager.sendExtraCommand(LocationManager.GPS_PROVIDER,
                "delete_aiding_data", extras);
    }

    @Override
    public void onBrake() {
        // EventBus.getDefault().post(event)

        if (mqttProxy != null) {
            try {
                AlarmData alarmData = new AlarmData();
                alarmData.put(AlarmData.AlarmType.ALARM_DECELERATE, 1);
                mqttProxy.sendAlarmReport(alarmData);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
        // 锁定文件
        Intent intentRecord = new Intent();
        intentRecord.setAction("lock_record_file");
        sendBroadcast(intentRecord);
        Log.i(TAG, "捕捉到一个急减速");
        sp.setGsensorDecCount(sp.getGsensorDecCount() + 1);
    }

    @Override
    public void onAccelerate() {

        sp.setGsensorAccCount(sp.getGsensorAccCount() + 1);
        Log.i(TAG, "捕捉到一个急加速");

        if (mqttProxy != null) {
            try {
                AlarmData alarmData = new AlarmData();
                alarmData.put(AlarmData.AlarmType.ALARM_ACCELERATE, 1);
                mqttProxy.sendAlarmReport(alarmData);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }

    class ActionReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, final Intent intent) {
            if (com.cxb.utils.Constants.CXBBroadcast.SHAREVIDEO.equals(intent
                    .getAction())
                    || com.cxb.utils.Constants.CXBBroadcast.SHAREPICTURE
                    .equals(intent.getAction())) {
                if (intent.getStringExtra("share_file") != null)
                    if (mqttProxy != null) {

                        new Thread() {
                            public void run() {
                                try {
                                    mqttProxy
                                            .sendMediaUpload(
                                                    intent.getStringExtra("share_file"),
                                                    UploadType.UPLOAD_SHARE,
                                                    System.currentTimeMillis());
                                } catch (RemoteException e) {
                                    e.printStackTrace();
                                }
                            }

                            ;
                        }.start();

                    }

            }
            if (com.cxb.utils.Constants.CXBBroadcast.ACTION_SEND_SHUTDOWN_IMAGE
                    .equals(intent.getAction())) {
                if (intent.getStringExtra("EXTRA_IMAGE") != null)
                    if (mqttProxy != null) {

                        new Thread() {
                            public void run() {
                                try {
                                    mqttProxy.sendTrackStopImage(intent
                                            .getStringExtra("EXTRA_IMAGE"));
                                } catch (RemoteException e) {
                                    e.printStackTrace();
                                }
                            }

                            ;
                        }.start();

                    }

            }
        }

    }

    public void bindMqttService() {
        mqttProxy = new MqttServiceProxy(getApplicationContext());
        mqttProxy.bindService();
        mqttProxy.registerCallback(new MqttCallBack(this),
                MqttServiceEvent.RX_CONFIG_STATUS,
                MqttServiceEvent.RX_BIND_STATUS,
                MqttServiceEvent.RX_GROUP_STATUS,
                MqttServiceEvent.RX_CHARGE_STATUS,
                MqttServiceEvent.RX_SYSTEM_REQUEST,
                MqttServiceEvent.RX_NAVI_REQUEST,
                MqttServiceEvent.RX_TRACK_REQUEST,
                MqttServiceEvent.RX_MONITOR_REQUEST);
        // 检查ota升级

//		mHandler.postDelayed(new Runnable() {
//
//			@Override
//			public void run() {
//				try {
//
//					ConfigStatus configStatus = mqttProxy.getConfigStatus();
//					if (configStatus.otaStatus != null) {
//						UpdateUtils.startUpdate(CXBMainService.this,
//								configStatus.otaStatus);
//					}
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//
//			}
//		}, 60000);
    }

    public static MqttServiceProxy getMqttProxy() {
        return mqttProxy;
    }
}
